#ifndef MOTOR_H
#define MOTOR_H

#include "ti_msp_dl_config.h"
#include <stdint.h>
#include <stdbool.h>

// 电机方向定义
typedef enum {
    MOTOR_DIRECTION_FORWARD = 0,
    MOTOR_DIRECTION_BACKWARD = 1,
    MOTOR_DIRECTION_BRAKE = 2,
    MOTOR_DIRECTION_COAST = 3
} motor_direction_t;

// 电机通道定义
typedef enum {
    MOTOR_CHANNEL_LEFT = 0,
    MOTOR_CHANNEL_RIGHT = 1
} motor_channel_t;

// PWM占空比范围定义
#define MOTOR_PWM_PERIOD        640
#define MOTOR_PWM_MIN_DUTY      0
#define MOTOR_PWM_MAX_DUTY      640
#define MOTOR_PWM_50_PERCENT    320

// 电机控制函数声明
void motor_init(void);
void motor_set_speed(motor_channel_t channel, motor_direction_t direction, uint16_t speed);
void motor_set_left_speed(motor_direction_t direction, uint16_t speed);
void motor_set_right_speed(motor_direction_t direction, uint16_t speed);
void motor_brake_all(void);
void motor_coast_all(void);
void motor_move_forward(uint16_t speed);
void motor_move_backward(uint16_t speed);
void motor_turn_left(uint16_t speed);
void motor_turn_right(uint16_t speed);
void motor_stop(void);

// PWM控制函数
void motor_set_pwm_duty(uint8_t channel, uint16_t duty);
uint16_t motor_get_pwm_duty(uint8_t channel);

// GPIO控制函数
void motor_set_bridge_state(motor_channel_t channel, bool high_side, bool low_side);

// TB6612 STBY引脚控制函数
void motor_enable_system(void);     // 启用电机系统（STBY=高电平）
void motor_disable_system(void);    // 禁用电机系统（STBY=低电平）
bool motor_is_system_enabled(void); // 检查电机系统是否启用

#endif // MOTOR_H